import type { DataTableColumns } from 'naive-ui'
import type { CreateColumsOptions } from '@/types/fcform'
import { NImage } from 'naive-ui'

export const createColums = ({ handDel, action }: CreateColumsOptions): DataTableColumns => {
  return [
    {
      title: '标题',
      key: 'publicName',
      width: 300,
    },
    {
      title: '值',
      key: 'publicValue',
      render(row) {
        if (row.publicKey.includes('FILE') || row.publicKey.includes('RICH')) {
          return '--'
        }
        if (row.publicKey.includes('IMAGE')) {
          return h(NImage, {
            src: row.publicValue,
            width: 40,
            height: 40,
            objectFit: 'cover',
          })
        }
        return row.publicValue
      },
    },
    {
      title: '操作',
      key: 'total',
      align: 'center',
      width: 150,
      render(row) {
        const childerArr = []
        const editBtn = fastUnit.createBtn('编辑', {
          type: 'warning',
          onClick: () => action.default(row),
        })
        if (commonUnit.auth('sys_syspublicparam_edit')) {
          childerArr.push(editBtn)
        }
        const delBtn = fastUnit.createBtn('删除', {
          type: 'error',
          onClick: () => handDel(row),
        })
        if (commonUnit.auth('sys_syspublicparam_del')) {
          childerArr.push(delBtn)
        }
        return h('div', childerArr)
      },
    },
  ]
}
